﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcmyjobs.Web.enprise
{
    public partial class ListReward : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Application["webname"] != null)
                {
                    this.Title = string.Format("单位管理中心—职位管理：悬赏招聘  {0}", Application["webname"].ToString());
                }
                int enterprise_bid = -1;

                if (Session["enterprise_bid"] != null)
                {
                    enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);

                    Bind(enterprise_bid);

                }
                else
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请先登陆！", "EnterpriseLogin.html");
                }

            }

        }

        private void Bind(int enterprise_bid)
        {
            int count = 0;

            DataSet ds = new lcmyjobs.BLL.enterprise_reward().GetReward(enterprise_bid, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out count);

            if (ds.Tables[1].Rows.Count > 0)
            {
                this.lbl_title.Text = " " + ds.Tables[1].Rows[0]["name"].ToString();
                
            }


            if (count == 0)
            {
                this.pnl_ts1.Visible = false;
                this.pnl_ts2.Visible = true;
                this.lblhint.Text = "您快捷找到：适合的、满意的、同您的招聘职位吻合的人才，建议您选择悬赏招聘，您将有机会借助猎手人脉资源关系，及聊城就业网悬赏服务，被推荐合适的人才";
            }
            else
            {
                this.pnl_ts1.Visible = true;
                this.pnl_ts2.Visible = false;
                this.lblhint.Text = "您已申请悬赏招聘，借助猎手人脉资源关系及聊城就业网悬赏服务，我们会尽快为您推荐适合的人才！";
            }

            this.lbl_xszw.Text = count.ToString();

            this.AspNetPager1.RecordCount = count;

            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "del")
            {
                if (e.CommandArgument != null)
                {
                    int enterprise_reward_id = Convert.ToInt32(e.CommandArgument);

                    lcmyjobs.BLL.enterprise_reward er = new BLL.enterprise_reward();

                    if (er.Delete(enterprise_reward_id))
                    {
                        int enterprise_bid = -1;

                        if (Session["enterprise_bid"] != null)
                        {
                            enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);

                            Bind(enterprise_bid);

                        }
                    }

                }
            }
            if (e.CommandName == "upd")
            {
                if (e.CommandArgument != null)
                {
                    int enterprise_reward_id = Convert.ToInt32(e.CommandArgument);

                    Session["enterprise_reward_id"] = enterprise_reward_id;

                    Response.Redirect("ModifyReward.html");

                }
            }
            if (e.CommandName == "look")
            {
                if (e.CommandArgument != null)
                {
                    int enterprise_reward_id = Convert.ToInt32(e.CommandArgument);

                    Session["enterprise_rid"] = enterprise_reward_id;

                    Response.Redirect("ModifyJobs.html");

                }
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            int enterprise_bid = -1;
            if (Session["enterprise_bid"] != null)
            {
                enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);

                Bind(enterprise_bid);

            }
        }
    }
}